﻿#region Usings
using System;
using System.Text.RegularExpressions;
#endregion

namespace LongNet.Web.Email.MIME
{
    /// <summary>
    /// Attributes associated with fields
    /// </summary>
    public class Attribute
    {
        #region Constructors
        /// <summary>
        /// Constructor
        /// </summary>
        public Attribute()
        {
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="AttributeText">Text of the attribute</param>
        public Attribute(string AttributeText)
        {
            string[] Splitter = { "=" };
            string[] Values = AttributeText.Split(Splitter, StringSplitOptions.None);
            if (Values.Length == 2)
            {
                Name = Values[0];
                Value = Values[1];
            }
            else if (Values.Length > 2)
            {
                Name = Values[0];
                Value = Values[1];
                for (int x = 2; x < Values.Length; ++x)
                {
                    Value += "=" + Values[x];
                }
            }
            else
            {
                Value = Values[0];
            }
            Regex TempReg = new Regex("\r\n*");
            Name = TempReg.Replace(Name, "");
            TempReg = new Regex("\t*");
            Name = TempReg.Replace(Name, "");
            TempReg = new Regex(Regex.Escape(" ") + "*");
            Name = TempReg.Replace(Name, "");
        }
        #endregion

        #region Public Properties
        private string _Name="";
        private string _Value="";
        /// <summary>
        /// Name of the attribute
        /// </summary>
        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        /// <summary>
        /// Value of the attribtue
        /// </summary>
        public string Value
        {
            get { return _Value; }
            set { _Value = value; }
        }
        #endregion
    }
}
